var WshShell = new ActiveXObject("WScript.Shell");
var operaNextTab = "2";
var mozillaNextTab = "^{TAB}";
var nextTabCmd = operaNextTab;
var waves = 8;
var minDelay= 90;
var maxDelay = 130;
var appaOpera = "- Opera";
var appaMozilla = "Firefox";
var appaChrome = "Chrome"
var appActivate = appaOpera;
var wavesInGroup = 4;
var isGroupWaves = true;
var grDelayMin = 600;
var grDelayMax = 800;
var fstWaveCoerce=0;




for (var i = 0, L = WScript.Arguments.length; i < L; i++)
{
var arg = WScript.Arguments(i);
switch(i)
{
case 0:
if (arg == "opera")
{
nextTabCmd = operaNextTab;
appActivate = appaOpera;
}
else if(arg == "mozilla")
{
nextTabCmd = mozillaNextTab;
appActivate = appaMozilla;
}
else if (arg == "chrome")
{
nextTabCmd = mozillaNextTab;
appActivate = appaChrome;

}
break;
case 1:
waves = parseInt(arg);
break;
case 2:
minDelay = parseInt(arg);
break;
case 3:
maxDelay = parseInt(arg);
break;
case 4:
grDelayMin = parseInt(arg);
break;
case 5:
grDelayMax = parseInt(arg);
break;
case 6:
fstWaveCoerce = parseInt(arg);
}
}


if (maxDelay < minDelay)
	maxDelay = minDelay + 1;
if (grDelayMin < grDelayMax)
	grDelayMax = grDelayMin + 1; 

//for (var i=0; i<numAltTabs ;i++)
//	WshShell.SendKeys( "%{TAB}")
WshShell.AppActivate(appActivate)
WScript.Sleep(1000)
var delays = [];
for (var i=0;i<waves;i++)
{
var delay = isGroupWaves && ((i+1)%4 == 0)
	? grDelayMin + Math.random()*(grDelayMin - grDelayMax )
	: (minDelay + Math.random()*(maxDelay-minDelay));
	if (i%4 == 0) delay+=fstWaveCoerce;
	delays.push(delay);
}

for (var i=0;i<waves;i++)
{
WshShell.SendKeys("{ENTER}");
WScript.Sleep(10);
WshShell.SendKeys (nextTabCmd);
WScript.Sleep(delays[i])
}
